package com.qlk.odcinterface.service.impl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.qlk.odcinterface.domain.PmsProductPromotionItem;
import com.qlk.odcinterface.domain.query.PmsProductPromotionItemQuery;
import com.qlk.odcinterface.manager.PmsProductPromotionItemManager;
import com.qlk.odcinterface.service.PmsProductPromotionItemService;
import com.qlk.odcinterface.utils.exceptions.ExistedException;
import com.qlk.common.utils.page.PageUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.perf4j.aop.Profiled;
 
/**
 * PmsProductPromotionItemService接口的实现类
 * 
 * @author zhaoyanan
 * @version 2016-4-14 13:22:58
 * 
 */
@Service
public class PmsProductPromotionItemServiceImpl implements PmsProductPromotionItemService {

    /** LOG */
    private static final Log LOG = LogFactory.getLog(PmsProductPromotionItemServiceImpl.class);

    @Autowired
    private PmsProductPromotionItemManager pmsProductPromotionItemManager;

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsProductPromotionItemService.batchInsert")
    public boolean insert(List<PmsProductPromotionItem> pmsProductPromotionItemList) {
        boolean resultFlag = false;
        try {
            if (CollectionUtils.isNotEmpty(pmsProductPromotionItemList)) {
                resultFlag = pmsProductPromotionItemManager.insert(pmsProductPromotionItemList);
            } else {
                LOG.warn("PmsProductPromotionItemServiceImpl#batchInsert failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsProductPromotionItemServiceImpl#batchInsert has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsProductPromotionItemService.insert")
    public boolean insert(PmsProductPromotionItem pmsProductPromotionItem) {
        boolean resultFlag = false;
        try {
            if (null != pmsProductPromotionItem) {
                if (pmsProductPromotionItemManager.exist(pmsProductPromotionItem)) {
                    throw new ExistedException();
                }
                resultFlag = pmsProductPromotionItemManager.insert(pmsProductPromotionItem);
            } else {
                LOG.warn("PmsProductPromotionItemServiceImpl#insert failed, param is illegal.");
            }
        } catch (ExistedException e) {
            LOG.warn("PmsProductPromotionItemServiceImpl#insert failed, pmsProductPromotionItem has existed.");
            throw e;
        } catch (Exception e) {
            LOG.error("PmsProductPromotionItemServiceImpl#insert has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsProductPromotionItemService.update")
    public boolean update(PmsProductPromotionItem pmsProductPromotionItem) {
        boolean resultFlag = false;
        try {
            if (null != pmsProductPromotionItem && null != pmsProductPromotionItem.getId()) {
                resultFlag = pmsProductPromotionItemManager.update(pmsProductPromotionItem);
            } else {
                LOG.warn("PmsProductPromotionItemServiceImpl#update failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsProductPromotionItemServiceImpl#update has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsProductPromotionItemService.queryPmsProductPromotionItemList")
    public List<PmsProductPromotionItem> queryPmsProductPromotionItemList(PmsProductPromotionItemQuery queryBean) {
        List<PmsProductPromotionItem> pmsProductPromotionItemList = null;
        try {
            pmsProductPromotionItemList = pmsProductPromotionItemManager.queryPmsProductPromotionItemList(queryBean);
        } catch (Exception e) {
            LOG.error("PmsProductPromotionItemServiceImpl#queryPmsProductPromotionItemList has error.", e);
        }
        return pmsProductPromotionItemList;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsProductPromotionItemService.queryPmsProductPromotionItemListWithPage")
    public List<PmsProductPromotionItem> queryPmsProductPromotionItemListWithPage(PmsProductPromotionItemQuery queryBean, PageUtil pageUtil) {
        List<PmsProductPromotionItem> pmsProductPromotionItemList = null;
        try {
            pmsProductPromotionItemList = pmsProductPromotionItemManager.queryPmsProductPromotionItemListWithPage(queryBean, pageUtil);
        } catch (Exception e) {
            LOG.error("PmsProductPromotionItemServiceImpl#queryPmsProductPromotionItemListWithPage has error.", e);
        }
        return pmsProductPromotionItemList;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsProductPromotionItemService.delete")
    public boolean delete(PmsProductPromotionItem pmsProductPromotionItem) {
        boolean resultFlag = false;
        try {
            if (null != pmsProductPromotionItem && null != pmsProductPromotionItem.getId()) {
                resultFlag = pmsProductPromotionItemManager.delete(pmsProductPromotionItem);
            } else {
                LOG.warn("PmsProductPromotionItemServiceImpl#delete param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsProductPromotionItemServiceImpl#delete has error.", e);
        }
        return resultFlag;
    }
    @Profiled(tag = "PmsProductPromotionItemService.deletePmsProductPromotionItem")
    public boolean deletePmsProductPromotionItem(PmsProductPromotionItem pmsProductPromotionItem) {
        boolean resultFlag = false;
        try {
            if (null != pmsProductPromotionItem && null != pmsProductPromotionItem.getId()) {
                resultFlag = pmsProductPromotionItemManager.deletePmsProductPromotionItem(pmsProductPromotionItem);
            } else {
                LOG.warn("PmsProductPromotionItemServiceImpl#deletePmsProductPromotionItem param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsProductPromotionItemServiceImpl#deletePmsProductPromotionItem has error.", e);
        }
        return resultFlag;
    }
    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsProductPromotionItemService.batchDelete")
    public boolean delete(PmsProductPromotionItem[] pmsProductPromotionItems) {
        boolean resultFlag = false;
        try {
            if (null != pmsProductPromotionItems && pmsProductPromotionItems.length > 0) {
                resultFlag = pmsProductPromotionItemManager.delete(pmsProductPromotionItems);
            } else {
                LOG.warn("PmsProductPromotionItemServiceImpl#batchDelete failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsProductPromotionItemServiceImpl#batchDelete has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsProductPromotionItemService.getPmsProductPromotionItemById")
    public PmsProductPromotionItem getPmsProductPromotionItemById(Long id) {
        PmsProductPromotionItem pmsProductPromotionItem = null;
        try {
            if (null != id) {
                pmsProductPromotionItem = pmsProductPromotionItemManager.getPmsProductPromotionItemById(id);
            } else {
                LOG.warn("PmsProductPromotionItemServiceImpl#getPmsProductPromotionItemById failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsProductPromotionItemServiceImpl#getPmsProductPromotionItemById has error.", e);
        }
        return pmsProductPromotionItem;
    }
}

